package com.kreao.korean.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.List;

@Data
@Entity
@Table(name = "words")
@EntityListeners(AuditingEntityListener.class)
@EqualsAndHashCode(exclude = {"user", "studyRecords"})
public class Word {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @NotBlank
    @Column(nullable = false)
    private String korean; // 韩语单词
    
    @NotBlank
    @Column(nullable = false)
    private String chinese; // 中文释义
    
    private String pronunciation; // 发音
    
    private String romanization; // 罗马音
    
    @Column(columnDefinition = "TEXT")
    private String examples; // 例句，JSON格式存储
    
    @Column(columnDefinition = "TEXT")
    private String notes; // 备注
    
    @Enumerated(EnumType.STRING)
    private WordCategory category; // 分类
    
    @Enumerated(EnumType.STRING)
    private WordLevel level; // 难度级别
    
    @Enumerated(EnumType.STRING)
    private WordType wordType; // 词性
    
    private Boolean isFavorite = false; // 是否收藏
    
    private Boolean isPublic = false; // 是否公开分享
    
    private Integer reviewCount = 0; // 复习次数
    
    private Integer correctCount = 0; // 正确次数
    
    private Integer wrongCount = 0; // 错误次数
    
    private Double accuracy = 0.0; // 正确率
    
    private LocalDateTime lastReviewTime; // 最后复习时间
    
    private LocalDateTime nextReviewTime; // 下次复习时间
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;
    
    @OneToMany(mappedBy = "word", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<StudyRecord> studyRecords;
    
    @CreatedDate
    private LocalDateTime createdAt;
    
    @LastModifiedDate
    private LocalDateTime updatedAt;
    
    public enum WordCategory {
        GRAMMAR("语法"),
        DAILY("日常"),
        TOPIK("TOPIK专项"),
        BUSINESS("商务"),
        TRAVEL("旅游"),
        FOOD("美食"),
        CULTURE("文化"),
        OTHER("其他");
        
        private final String description;
        
        WordCategory(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    public enum WordLevel {
        BEGINNER("初级"),
        INTERMEDIATE("中级"),
        ADVANCED("高级");
        
        private final String description;
        
        WordLevel(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    public enum WordType {
        NOUN("명사"),           // 名词
        VERB("동사"),           // 动词
        ADJECTIVE("형용사"),    // 形容词
        ADVERB("부사"),         // 副词
        PARTICLE("조사"),       // 助词
        CONJUNCTION("접속사"),  // 连词
        INTERJECTION("감탄사"), // 感叹词
        NUMERAL("수사"),        // 数词
        PRONOUN("대명사"),      // 代词
        OTHER("기타");          // 其他
        
        private final String korean;
        
        WordType(String korean) {
            this.korean = korean;
        }
        
        public String getKorean() {
            return korean;
        }
    }
} 